<?php
// 网站用户管理
namespace Admin\Controller;

class UsersController extends LoginController {
	public function __construct() {
		parent::__construct ();
		layout ( false );
	}
	
	/**
	 * 用户管理
	 * 
	 * @access public
	 * @param char $_POST
	 *        	用户提交信息
	 * @param int $id
	 *        	用户id
	 */
	public function index() {
		if (! empty ( $_POST )) {
			$this->db = D ( "Users" );
			$arr = $_POST;
			$arr ['password'] = md5 ( $arr ['password'] );
			if (! $_POST ['id']) {
				$arr ['up_date'] = $arr ['creat_date'] = date ( "Y-m-d H:i:s" );
				$arr ['status'] = 1;
				$this->db->add ( $arr );
			} else {
				$this->db->where ( array (
						'id' => $arr ['id'] 
				) )->save ( $arr );
			}
		}
		// 读取用户信息
		$this->db = D ( 'Users' );
		$where = array (
				'status' => 1 
		);
		$userinfo = $this->db->getInfo ( $where );
		$this->assign ( array (
				"userinfo" => $userinfo 
		) );
		
		$this->display ( "index" );
	}
	
	/**
	 * 检查用户id
	 * 
	 * @access public
	 *         var user_id 用户账号
	 */
	public function checkUserid() {
		$user_id = $_POST ['user_id'];
		$this->db = D ( 'Users' );
		$userinfo = $this->db->getInfo ( array (
				'user_id' => $user_id 
		) );
		echo count ( $userinfo );
		exit ();
	}
	
	/**
	 * 获取用户信息
	 * 
	 * @access public
	 * @param char $id
	 *        	用户ID
	 */
	public function getUser() {
		$id = $_POST ['id'];
		$this->db = D ( 'Users' );
		$data = $this->db->select ( $id );
		$this->ajaxReturn ( $data [0] );
	}
	
	/**
	 * 删除用户
	 * 
	 * @access public
	 * @param int $id
	 *        	用户ID
	 */
	public function deUser() {
		$id = $_POST ['id'];
		$this->db = D ( 'Users' );
		$data = array (
				'status' => 2 
		);
		$this->db->where ( array (
				'id' => $id 
		) )->save ( $data );
		echo true;
	}
}

?>